<template>
    <!-- 设置 - 管理员设置 -->
    <div>
        <el-header height="auto">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/Main/index' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>
                    <a>设置</a>
                </el-breadcrumb-item>
                <el-breadcrumb-item>管理员设置</el-breadcrumb-item>
            </el-breadcrumb>
            <el-dropdown placement="bottom">
                <span class="el-dropdown-link">
                    <img src="../../assets/img/default.jpg" alt />
                </span>
                <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item @click.native="goToIndex">首页</el-dropdown-item>
                    <el-dropdown-item @click.native="LogOUt">退出</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
        </el-header>
        <main>
            <header class="admin_title">管理员信息</header>
            <div class="admin_set">
                <ul>
                    <li>
                        <h4>姓名：</h4>
                    </li>
                    <li>
                        <h4>注册时间：</h4>
                    </li>
                    <li>
                        <h4>管理员权限：</h4>
                    </li>
                    <li>
                        <h4>管理员 ID：</h4>
                    </li>
                    <li>
                        <h4>更换头像：</h4>
                        <el-upload
                            class="avatar-uploader"
                            action="https://jsonplaceholder.typicode.com/posts/"
                            :show-file-list="false"
                            :on-success="handleAvatarSuccess"
                            :before-upload="beforeAvatarUpload"
                        >
                            <img v-if="imageUrl" :src="imageUrl" class="avatar" />
                            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                        </el-upload>
                    </li>
                </ul>
            </div>
        </main>
    </div>
</template>
<script>
export default {
    data() {
        return {
            imageUrl: ""
        };
    },
    methods: {
        // 头像上传
        handleAvatarSuccess(res, file) {
            this.imageUrl = URL.createObjectURL(file.raw);
        },
        beforeAvatarUpload(file) {
            const isJPG = file.type === "image/jpeg";
            const isLt2M = file.size / 1024 / 1024 < 2;
            if (!isJPG) {
                this.$message.error("上传头像图片只能是 JPG 格式!");
            }
            if (!isLt2M) {
                this.$message.error("上传头像图片大小不能超过 2MB!");
            }
            return isJPG && isLt2M;
        },
        // 跳转至首页
        goToIndex() {
            this.$router.push({ path: "/Main/index" });
        },
        // 退出登录
        LogOUt() {
            this.$router.push({ path: "/" });
        }
    }
};
</script>
<style scoped>
.admin_title {
    padding: 20px 0;
    font-size: 24px;
    color: #666;
    text-align: center;
}
.admin_set {
    color: #666;
    max-width: 650px;
    margin: 0 auto;
    border-radius: 10px;
    background-color: #f9fafc;
}

.admin_set li {
    list-style: none;
    padding: 20px;
}
.admin_set li h4 {
    font-weight: normal;
}

.avatar-uploader {
    padding-top: 10px;
}
</style>